package com.base.cn.platform.os.controller.web.qa.question;

import com.base.cn.platform.os.common.WebBaseController;
import com.base.cn.platform.os.service.course.qa.question.QaQuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import java.math.BigDecimal;
import java.util.Map;

/**
 * PC端问答系统--我的问答Controller
 *
 * @author LIZHIPENG
 * @create 2018-05-22 上午 10:05
 */
@Controller
@RequestMapping("/web/uc/qa/question")
public class WebMyQuestionController extends WebBaseController {

    @Autowired
    private QaQuestionService qaQuestionService;
    /**
     * 去往我的问答页面
     * @param model
     * @param request
     * @return
     */
    @RequestMapping("/toMyQuestionView")
    public String toMyQuestionView(Model model, HttpServletRequest request){
        return resultPage("/qa/question/qa-my-question-list");
    }

    /**
     * ajax查询我的问答列表
     * @param model
     * @param request
     * @param params 查询类型：1.我提问的-免费，2.我回答(评论)的，3.我提问的-付费，4.我围观的
     * @return
     */
    @RequestMapping("/ajaxQueryMyQuestionList")
    public String ajaxQueryMyQuestionList(Model model,
                                          HttpServletRequest request,
                                          @RequestParam(value = "currentPage", required = false, defaultValue = "1") int currentPage,
                                          @RequestBody Map<String, Object> params){
        BigDecimal userId = webMobileLoginUtil.getLoginUserId(request);
        String _queryType = (String) params.get("queryType");
        int queryType = Integer.valueOf(_queryType);
        Map<String, Object> dataMap = qaQuestionService.queryMyQuestionList(currentPage, 10, userId, queryType, false, true, false, false, false, true, false);
        model.addAttribute("dataMap", dataMap);
        return resultPage("/qa/question/ajax-qa-question-list");
    }
}
